namespace IniTechCaash.Domain.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialCreate : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Accounts",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Balance = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Description = c.String(),
                        IsEnabled = c.Boolean(nullable: false),
                        Name = c.String(nullable: false, maxLength: 256),
                        Number = c.String(nullable: false, maxLength: 9),
                        Type = c.Int(nullable: false),
                        CreatedBy = c.String(nullable: false, maxLength: 256),
                        CreatedDate = c.DateTime(nullable: false),
                        LastModifiedBy = c.String(nullable: false, maxLength: 256),
                        LastModifiedDate = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.ActivityLogs",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        CreatedBy = c.String(nullable: false, maxLength: 256),
                        LogDate = c.DateTime(nullable: false),
                        Message = c.String(nullable: false, maxLength: 256),
                        ObjectReferenceId = c.Int(nullable: false),
                        ObjectReferenceType = c.String(nullable: false, maxLength: 64),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.JournalEntries",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        CreatedBy = c.String(nullable: false, maxLength: 256),
                        CreatedDate = c.DateTime(nullable: false),
                        LastModifiedBy = c.String(nullable: false, maxLength: 256),
                        LastModifiedDate = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.JournalEntryLines",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Amount = c.Decimal(nullable: false, precision: 18, scale: 2),
                        Description = c.String(maxLength: 128),
                        Side = c.Int(nullable: false),
                        Account_Id = c.Int(),
                        JournalEntry_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Accounts", t => t.Account_Id)
                .ForeignKey("dbo.JournalEntries", t => t.JournalEntry_Id)
                .Index(t => t.Account_Id)
                .Index(t => t.JournalEntry_Id);
            
            CreateTable(
                "dbo.SourceDocuments",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        JournalEntry_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.JournalEntries", t => t.JournalEntry_Id, cascadeDelete: true)
                .Index(t => t.JournalEntry_Id);
            
            CreateTable(
                "dbo.UserRoles",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        RoleName = c.String(),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.Users",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        UserName = c.String(nullable: false, maxLength: 256),
                        UserPassword = c.String(nullable: false, maxLength: 256),
                        CreatedBy = c.String(nullable: false, maxLength: 256),
                        CreatedDate = c.DateTime(nullable: false),
                        LastModifiedBy = c.String(nullable: false, maxLength: 256),
                        LastModifiedDate = c.DateTime(nullable: false),
                    })
                .PrimaryKey(t => t.Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.SourceDocuments", "JournalEntry_Id", "dbo.JournalEntries");
            DropForeignKey("dbo.JournalEntryLines", "JournalEntry_Id", "dbo.JournalEntries");
            DropForeignKey("dbo.JournalEntryLines", "Account_Id", "dbo.Accounts");
            DropIndex("dbo.SourceDocuments", new[] { "JournalEntry_Id" });
            DropIndex("dbo.JournalEntryLines", new[] { "JournalEntry_Id" });
            DropIndex("dbo.JournalEntryLines", new[] { "Account_Id" });
            DropTable("dbo.Users");
            DropTable("dbo.UserRoles");
            DropTable("dbo.SourceDocuments");
            DropTable("dbo.JournalEntryLines");
            DropTable("dbo.JournalEntries");
            DropTable("dbo.ActivityLogs");
            DropTable("dbo.Accounts");
        }
    }
}
